<%@ page contentType="text/html;charset=UTF-8" language="java" %>

    <% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
        + request.getServerPort() + path + "/" ; %>
        <!DOCTYPE html>

        <head>
            <base href="<%=basePath%>">
            <title>报价书</title>
            <meta http-equiv="pragma" content="no-cache">
            <meta http-equiv="cache-control" content="no-cache">
            <meta http-equiv="expires" content="0">
            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
            <meta http-equiv="description" content="This is my page">
        </head>

        <body>
            <style>
                .tdText {
                    text-align: right;
                    width: 400px;
                    height: 20px;
                }
            </style>
        </body>
        <%@ include file="/WEB-INF/jsp/common/header.jsp" %>
            <%@ include file="/WEB-INF/jsp/common/loadDiv.jsp" %>

                <script type="text/javascript">
                    $(function () {
                        $('#startTime').datebox('setValue', getBeforeCurrentDate90Days());
                        $('#endTime').datebox('setValue', getNowFormatDate());
                        bingGrid();
                    });

                </script>
                <div class="query_criteria" id="query_criteria">
                    <div style="margin: 5px 0px">
                        <%-- 搜索框 --%>
                            <label style="font-size: 12px;">创建时间：</label> <input class="easyui-datebox" name="startTime"
                                id="startTime"
                                data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                value="" style="width: 150px"> <label style="font-size: 10px;">~</label> <input
                                class="easyui-datebox" name="endTime" id="endTime"
                                data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                style="width: 150px" /> <label style="margin-left: 20px; font-size: 12px;">状态：</label>
                            <input class="easyui-combobox" id="status" name="status" style="width: 80px;" data-options="valueField: 'value',editable:false,
		textField: 'label',panelHeight:'auto',data: [{
			label: '全部',
			value: ''
		},{
			label: '待报价',
			value: '0',
			selected:true
		},{
			label: '已报价',
			value: '1'
		}]">
                            <a id="search" style="margin-left: 30px" href="javascript:void(0)" class="easyui-linkbutton"
                                data-options="iconCls:'icon-search'" onclick="selectList()">查询</a><input type="file"
                                id="uploadMM" accept="" onchange="changeMM()" style="display: none;" />
                    </div>
                    <table id="dg"></table>
                    <div id="supplyOfferWindow" class="easyui-window" closed="true" modal="true" title="供应商报价"
                        style="width: 900px; height: 400px; padding: 5px 5px">
                        <form id="supplyOfferForm">
                            <div class="easyui-tabs" id="tabs" style="width: 875px; height: 350px">
                                <div title="基本信息">
                                    <table>
                                        <tr style="margin-bottom: 10px">
                                            <td colspan="1" class="tdText"><input id="infId" type="hidden"
                                                    class="easyui-validatebox textbox" style="width: 60%"> <label
                                                    style="width: 40%; text-align: right;">询价名称：</label> <input
                                                    id="inqName" class="easyui-validatebox textbox" style="width: 60%">
                                                <input id="inqId" type="hidden" class="easyui-validatebox textbox"
                                                    style="width: 60%">
                                            </td>
                                            <td colspan="1" class="tdText"><label
                                                    style="width: 40%; text-align: right;">联系人：</label> <input
                                                    id="infContact" class="easyui-validatebox textbox"
                                                    style="width: 60%" data-options="required:true"></td>
                                            <td colspan="1" class="tdText"><label
                                                    style="width: 40%; text-align: right;">联系电话：</label> <input
                                                    id="infContactTel" class="easyui-validatebox textbox"
                                                    style="width: 60%" data-options="required:true"></td>
                                            <%--<td colspan="1" class="tdText">
                                                <label style="width:40%;text-align:right;">报价开始时间：</label>
                                                <input id="inqStartTime" class="easyui-datebox" style="width: 60%">
                                                </td>
                                                <td colspan="1" class="tdText">
                                                    <label style="width:40%;text-align:right;">报价结束时间：</label>
                                                    <input id="inqEndTime" class="easyui-datebox" style="width: 60%">
                                                </td>
                                                <td colspan="1" class="tdText">
                                                    <label style="width:40%;text-align:right;">提交时间：</label>
                                                    <input id="inqOfrTime" class="easyui-datebox" style="width: 60%">
                                                </td>--%>
                                        </tr>
                                        <tr style="margin-bottom: 10px">

                                            <td colspan="1" class="tdText"><label
                                                    style="width: 40%; text-align: right;">备注：</label> <input
                                                    id="remark" class="easyui-textbox"
                                                    data-options="readonly:false,multiline:true"
                                                    style="width: 60%; height: 100px">
                                            </td>
                                            <%-- <td colspan="1" class="tdText">
                                                <label style="width:40%;text-align:right;">创建时间：</label>
                                                <input id="createTime" class="easyui-datebox" style="width: 60%">
                                                </td>
                                                <td colspan="1" class="tdText">
                                                    <label style="width:40%;text-align:right;">创建人：</label>
                                                    <input id="createName" class="easyui-validatebox textbox"
                                                        style="width: 60%">
                                                </td>--%>
                                        </tr>
                                        <%-- <tr style="margin-bottom: 10px">

                                            <td colspan="1" class="tdText">
                                                <label style="width:40%;text-align:right;">更新人：</label>
                                                <input id="updateName" class="easyui-validatebox textbox"
                                                    style="width: 60%">
                                            </td>
                                            <td colspan="1" class="tdText">
                                                <label style="width:40%;text-align:right;">更新时间：</label>
                                                <input id="updateTime" class="easyui-datebox" style="width: 60%">
                                            </td>
                                            </tr>--%>
                                    </table>

                                </div>
                                <div title="物资报价明细">
                                    <table id="supplMMOfferList"></table>
                                </div>
                            </div>
                        </form>
                    </div>

                </div>
                <script>
                    /**
                     *  按条件查询报价列表
                     */
                    function selectList() {
                        var startTime = $('#startTime').datebox('getValue')
                        var endTime = $('#endTime').datebox('getValue')
                        var offerStatus = $('#status').combobox('getValue');
                        var dg = $('#dg');
                        dg.datagrid('enableFilter');
                        dg.datagrid('load', {
                            startTime: startTime ? startTime : '',
                            endTime: endTime ? endTime : '',
                            status: offerStatus ? offerStatus : '',
                            inqMode: '线下报价'
                        });
                    }

                    var editIndex = undefined;

                    // 行编辑结束
                    function endEditing() {
                        if (editIndex == undefined) {
                            return true
                        }
                        if ($('#supplMMOfferList').datagrid('validateRow', editIndex)) {
                            $('#supplMMOfferList').datagrid('endEdit', editIndex);
                            editIndex = undefined;
                            return true;
                        } else {
                            alert('请先完成本行必填数据输入');
                            return false;
                        }
                    }

                    // 待报价物资明细列表的列
                    const notOfferedColmus = [[
                        {
                            field: 'infId',
                            title: '供应商id',
                            hidden: true,
                            formatter: function (val, rec, index) {
                                return val ? val : '';
                            }
                        },
                        {
                            field: 'inqId',
                            title: '询价id',
                            hidden: true,
                            formatter: function (val, rec, index) {
                                return val ? val : '';
                            }
                        },
                        {
                            field: 'mmId',
                            title: '物资id',
                            hidden: true,
                            formatter: function (val, rec, index) {
                                return val ? val : '';
                            }
                        },
                        {
                            field: 'mmMain',
                            title: '主特征',
                            sortable: true,
                            width: 100,
                            /*editor: {
                                type: 'numberbox',
                                options: {
                                    precision: 0
                                }
                            },*/
                            formatter: function (val, rec) {
                                return val ? unescape(val) : ''
                            }
                        },
                        {
                            field: 'planId',
                            title: '采购计划_id',
                            hidden: true,
                            width: 100,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        {
                            field: 'gramId',
                            title: '采购方案ID',
                            hidden: true,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        /* {
                             field: 'status',
                             title: '状态',
                             sortable: true,
                             formatter: function (val, rec) {
                                 return unescape(val ? val : '')
                             }
                         },*/
                        {
                            field: 'mmUnit',
                            title: '计量单位',
                            sortable: true,
                            width: 100,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        {
                            field: 'mmUnitDetail',
                            title: '计量单位描述',
                            sortable: true,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        {
                            field: 'gramPurNum',
                            title: '招标数量',
                            sortable: true,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        {
                            field: 'inqOfrNum',
                            title: '报价数量',
                            sortable: true,
                            width: 100,
                            editor: { type: 'numberbox', options: { precision: 3 } },
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        {
                            field: 'inqOfrUnitPrice',
                            title: '含税单价',
                            width: 100,
                            sortable: true,
                            editor: { type: 'numberbox', options: { precision: 2 } },
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        {
                            field: 'inqOfrTotalPrice',
                            title: '含税价格',
                            width: 100,
                            sortable: true,
                            // editor: {type: 'numberbox', options: {precision: 0}},
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        // {
                        //     field: 'inqTaxRate',
                        //     title: '税率',
                        //     width: 100,
                        //     // editor: {type: 'numberbox', options: {precision: 0}},
                        //     sortable: true,
                        //     formatter: function (val, rec) {
                        //         return unescape(val ? val : '')
                        //     }
                        // },
                        {
                            field: 'inqTaxNum',
                            title: '税码',
                            width: 120,
                            sortable: true,
                            editor: {
                                type: 'combobox',
                                options: {
                                    url: 'sysDict/queryItemByTypeName?dicName=税码',
                                    method: 'get',
                                    valueField: "dicValue",
                                    textField: "dicName",
                                    editable: false,
                                    required: true,
                                    onSelect: function (record) {
                                        // let proRow = $('#supplMMOfferList').datagrid('getSelected')
                                        // proRow.inqTaxRate = record.dicName
                                    }
                                }
                            },
                            formatter: function (val, rec) {
                                console.log("val----", val)
                                return val ? unescape(rec.inqTaxRate) : '';
                            }
                        },
                        {
                            field: 'inqDeliverDate',
                            title: '交货日期',
                            width: 100,
                            sortable: true,
                            editor: { type: 'datebox' },
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        /*  {
                              field: 'inqOfrExcludePrice',
                              title: '不含税价格',
                              editor: {type: 'numberbox', options: {precision: 0}},
                              sortable: true,
                              formatter: function (val, rec) {
                                  return unescape(val ? val : '')
                              }
                          },*/

                        {
                            field: 'createTime',
                            title: '创建时间',
                            sortable: true,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        /* {
                             field: 'updateTime',
                             title: '更新时间',
                             sortable: true,
                             formatter: function (val, rec) {
                                 return unescape(val ? val : '')
                             }
                         }*/
                        /* {
                             field: 'status',
                             title: '状态',
                             sortable: true,
                             formatter: function (val, rec) {
                                 let status = val ? val : '';
                                 return unescape(status == '0' ? '待提交' : '已提交');
                             }
                         }*/
                    ]];

                    /**
                     *打开供应商报价
                     */
                    function openOfferDetail(index) {
                        let dg = $('#dg')
                        const rows = dg.datagrid('getRows')
                        let row = rows[index]
                        setOfferDetailWindowValue(row)
                    }

                    /**
                     * 编辑报价信息
                     */
                    function editRow() {
                        let offerRow = $('#dg').datagrid('getSelected');
                        if (!offerRow) {
                            $.messager.alert('提示', '请选择一条数据');
                            return
                        }
                        if (+offerRow.status == 1) {
                            $.messager.alert('提示', '该报价已提交，不允许再次修改')
                            return
                        }

                        setOfferDetailWindowValue(offerRow, 'edit');
                    }

                    /**
                     * 报价详情(编辑)窗口赋值
                     */

                    function setOfferDetailWindowValue(item, action) {
                        console.log('item...', item)
                        if (+item.status != '1') {
                            $('#tabs').tabs({
                                tools: [
                                    {
                                        text: '保存',
                                        iconCls: 'icon-save',
                                        handler: function () {
                                            saveSupplyOfferMM('save');
                                        }
                                    }, {
                                        text: '提交',
                                        iconCls: 'icon-ok',
                                        handler: function () {
                                            $.messager.confirm('提示', '提交后无法再次编辑，确定要提交吗?',
                                                function (r) {
                                                    if (r) {
                                                        saveSupplyOfferMM('submit');
                                                    }
                                                });
                                        }
                                    }]
                            })
                        } else {
                            $('#tabs').tabs({
                                tools: []
                            })
                        }

                        $.ajax({
                            type: 'POST',
                            dataType: 'json',
                            url: 'purchase/offer/selectOfferMmList?inqId=' + item.inqId + '&infId=' + item.infId,
                            success: function (data) {
                                if (data.code != 60200) {
                                    $.messager.alert('消息', data.msg);
                                } else {
                                    $('#infId').val(item.infId)
                                    $('#inqName').val(item.inqName);
                                    $('#infContact').val(item.infContact);
                                    $('#infContactTel').val(item.infContactTel);
                                    $('#inqName').textbox({ disabled: true });
                                    $('#inqId').val(item.inqId);
                                    //  $('#inqOfrIncludePrice').numberbox('setValue', item.inqOfrIncludePrice);
                                    $('#inqOfrTime').datebox('setValue', item.inqOfrTime);
                                    $('#inqStartTime').datebox('setValue', item.inqStartTime);
                                    $('#inqEndTime').datebox('setValue', item.inqEndTime);
                                    $('#remark').val(item.remark);
                                    $('#createTime').datebox('setValue', item.createTime);
                                    $('#createName').val(item.createName);
                                    $('#gramDeptCode').val(item.gramDeptCode);
                                    $('#gramDeptName').val(item.gramDeptName);
                                    $('#gramGetDeptCode').val(item.gramGetDeptCode);
                                    $('#gramIsUrgent').val(item.gramIsUrgent);
                                    $('#gramFlowType').val(item.gramFlowType);
                                    $('#createTime').val(item.createTime);
                                    $('#createName').val(item.createName);
                                    //    $('#updateName').val(item.updateName);
                                    //   $('#updateTime').datebox('setValue', item.updateTime);
                                    // 构建物资报价明细的dataGrid
                                    const purchaseSupplyOfferMms = data.rows
                                    setMmsDatagird(purchaseSupplyOfferMms);

                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                $.messager.alert('消息', errorThrown);
                            }
                        })
                        $('#supplyOfferWindow').window('open');
                    }

                    // 构建物资明细dataGrid
                    function setMmsDatagird(data) {
                        for (let item of data) {
                            item.inqOfrNum = item.inqOfrNum ? item.inqOfrNum : item.gramPurNum;
                        }
                        let supplMMOfferList = $('#supplMMOfferList')
                        supplMMOfferList.datagrid({
                            //             fitColumns: true,
                            data: data,
                            iconCls: 'icon-application',
                            clientPaging: false,
                            filterDelay: 0,
                            width: 850,
                            height: 300,
                            nowrap: true,
                            rownumbers: true,
                            animate: false,
                            collapsible: false,
                            singleSelect: true,
                            frozenColumns: [
                                [
                                    {
                                        field: 'mmCode',
                                        title: '物资编码',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'mmDetail',
                                        title: '物资描述',
                                        sortable: true,
                                        width: 210,
                                        formatter: function (val, rec) {
                                            if (val) {
                                                return '<span title="' + val + '">' + val + '</span>';
                                            } else {
                                                return val;
                                            }
                                        }
                                    }
                                ]
                            ],
                            columns: notOfferedColmus,
                            onEndEdit: function (index, row) {
                                var ed = $(this).datagrid('getEditor', {
                                    index: index,
                                    field: 'inqTaxNum'
                                });
                                row.inqTaxRate = $(ed.target).combobox('getText');
                            },
                            // 行单击事件
                            onClickRow: function (index, rowData) {
                                if (+rowData.status == 1) {
                                    return $.message.alert('该条数据已提交，不可进行编辑');
                                }
                                if (editIndex != index) {
                                    if (endEditing()) {
                                        $('#supplMMOfferList').datagrid('selectRow', index).datagrid('beginEdit', index);
                                        editIndex = index;
                                    } else {
                                        $('#supplMMOfferList').datagrid('selectRow', editIndex);
                                    }
                                } else if (editIndex != undefined) {//如果不相等，说明已经打开编辑器了，需要关闭编辑器
                                    $('#supplMMOfferList').datagrid('endEdit', editIndex);
                                    editIndex = undefined;
                                }
                            },
                            onLoadSuccess: function () {

                            },
                            toolbar: [{
                                text: '一键填充',
                                iconCls: 'icon-down',
                                handler: function () {
                                    $.messager.confirm("提示", "确认向下复制第一行数据?", function (e) {
                                        if (e) {
                                            if (endEditing()) {
                                                var rows = $('#supplMMOfferList').datagrid('getRows');
                                                for (let i = 1; i < rows.length; i++) {
                                                    var row = rows[i];
                                                    // row.inqOfrNum = rows[0].inqOfrNum;
                                                    // row.inqOfrUnitPrice = rows[0].inqOfrUnitPrice;
                                                    // row.inqOfrTotalPrice = rows[0].inqOfrTotalPrice;
                                                    row.inqTaxRate = rows[0].inqTaxRate;
                                                    row.inqTaxNum = rows[0].inqTaxNum;
                                                    row.inqDeliverDate = rows[0].inqDeliverDate;
                                                    $('#supplMMOfferList').datagrid('updateRow', { index: i, row: row });
                                                    $('#supplMMOfferList').datagrid('refreshRow', i);
                                                }
                                                //                                         $('#mmOffers').datagrid('acceptChanges');
                                                // $('#mmOffers').datagrid('reload');
                                            }
                                        }
                                    })
                                }
                            }, '-', {
                                text: '导出',
                                iconCls: 'icon-export',
                                handler: function () {
                                    exportMmList();
                                }
                            }, '-', {
                                text: '导入',
                                iconCls: 'icon-up',
                                handler: function () {
                                    $("#uploadMM").click();
                                }
                            }],
                        });
                        supplMMOfferList.datagrid('enableFilter');
                    }

                    //导入
                    function changeMM() {
                        load();
                        let gramMmRows = $('#dg').datagrid('getSelected');
                        var files = $("#uploadMM").prop("files");
                        var item = files[0];
                        console.log('item', item);
                        var index = item.name.lastIndexOf(".");
                        //取出从index开始到最后的字符串，赋值给extension（extension就是该文件的类型）并且转换成小写，以上文为例，取出的则是".exe",
                        var extension = item.name.substring(index).toLowerCase();
                        //这里定义允许用户上传的文件类型
                        var allowedType = [".xlsx"];
                        //判断extension是否存在于allowedType中
                        for (var i = 0; i < allowedType.length; i++) {
                            if (allowedType[i] != extension) {
                                disLoad();
                                alert("不支持" + extension + "格式,请上车xlsx文件");
                                return;
                            }
                        }
                        var dataform = new FormData();
                        dataform.append("file", item);
                        var xmlhttp = null;
                        if (window.XMLHttpRequest) { // code for all new browsers
                            xmlhttp = new XMLHttpRequest();
                        } else if (window.ActiveXObject) {// code for IE5 and IE6
                            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        if (xmlhttp != null) {
                            xmlhttp.open("POST", "api/file/springUpload?fileRow="
                                + gramMmRows.inqId + "&fileTable=supply_offer_mm&fileName="
                                + item.name, true);
                            xmlhttp.setRequestHeader('token', localStorage
                                .getItem('token'));
                            xmlhttp.setRequestHeader('userType', localStorage
                                .getItem('userType'));
                            xmlhttp.send(dataform);
                            xmlhttp.onreadystatechange = callbackMethods;
                        } else {
                            alert("你的浏览器版本不兼容，请使用更高版本的浏览器");
                        }

                        function callbackMethods() {
                            disLoad();
                            if (xmlhttp.readyState == 4) {
                                if (xmlhttp.status == 200) {
                                    addMMData(gramMmRows);
                                }

                            } else {
                                if (xmlhttp.status == 500) {
                                }
                            }

                        }
                    }

                    function addMMData(gramMmRows) {
                        var model = {
                            fileRow: gramMmRows.inqId,
                            fileTable: 'supply_offer_mm',
                            infId: gramMmRows.infId
                        }
                        $.ajax({
                            type: "post",
                            dataType: "json",
                            url: 'purchase/offer/importMM',
                            data: JSON.stringify(model),
                            contentType: "application/json",
                            success: function (data) {
                                if (data.code == 60200) {
                                    editRow()
                                    $.messager.alert('消息', data.msg);
                                } else {
                                    $.messager.alert('消息', data.msg);
                                }
                                $("#uploadMM").val("");
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                $.messager.alert('消息', errorThrown);
                            }
                        })
                    }

                    // 导出采购计划列表
                    function exportMmList() {
                        let gramMmRows = $('#dg').datagrid('getSelected');
                        var form = [];
                        form.push('inqId=' + gramMmRows.inqId);
                        form.push('infId=' + gramMmRows.infId);
                        let url = 'api/purchase/offer/exportOfferMm'
                        let xhr = new XMLHttpRequest()
                        xhr.open('POST', url, true)
                        xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                        xhr.setRequestHeader('token', localStorage.getItem('token'));
                        xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                        xhr.responseType = 'blob'
                        xhr.onload = function () {
                            if (this.status == 200) {
                                let blob = this.response
                                let reader = new FileReader()
                                reader.readAsDataURL(blob)
                                reader.onload = function (e) {
                                    let a = document.createElement('a')
                                    a.download = '报价明细' + new Date().getTime() + '.xlsx'
                                    a.href = e.target.result
                                    $('body').append(a)
                                    a.click()
                                    $(a).remove()
                                }
                            }
                        }
                        xhr.send(form.join('&'))
                    }

                    // 保存/提交
                    function saveSupplyOfferMM(action) {
                        if (!$('#supplyOfferForm').form('validate')) {
                            alert('请完成必填项输入');
                            return;
                        }
                        let offerStatus = '0';
                        if (action == 'submit') {
                            offerStatus = "1";
                        }
                        // 1.首先关闭编辑器
                        $('#supplMMOfferList').datagrid('endEdit', editIndex);
                        editIndex = undefined;
                        // 2.获取物资明细
                        const supplMMOfferList = $('#supplMMOfferList').datagrid('getRows');
                        // 取得报价总数量与合计价格
                        let inqOfrNum = 0
                        let inqOfrTotalPrice = 0
                        if (supplMMOfferList != null && supplMMOfferList.length > 0) {
                            for (let i in supplMMOfferList) {
                                // 报价数量
                                let oferNum = supplMMOfferList[i].inqOfrNum ? Number(supplMMOfferList[i].inqOfrNum) : 0
                                // 报价单价
                                let oferPrice = supplMMOfferList[i].inqOfrUnitPrice ? Number(supplMMOfferList[i].inqOfrUnitPrice) : 0
                                // 报价总数量
                                inqOfrNum += oferNum
                                // 物资列的含税价格重新赋值
                                supplMMOfferList[i].inqOfrTotalPrice = oferPrice * oferNum
                                // 合计价格
                                inqOfrTotalPrice += oferPrice * oferNum
                            }
                        }
                        // 调用后台接口保存
                        let PurchaseSupplyOfferVO = {
                            inqId: $('#inqId').val(),
                            infId: $('#infId').val(),
                            infContactTel: $('#infContactTel').val(),
                            infContact: $('#infContact').val(),
                            status: offerStatus,
                            // 第一次报价总额
                            inqOfrTotalPrice: inqOfrTotalPrice,
                            // 第一次报价总数量
                            inqOfrNum: inqOfrNum,
                            purchaseSupplyOfferMms: supplMMOfferList
                        }
                        $.ajax({
                            type: "post",
                            dataType: "json",
                            url: 'purchase/offer/saveOfferMm',
                            data: JSON.stringify(PurchaseSupplyOfferVO),
                            contentType: "application/json",
                            success: function (data) {
                                if (data.code != 60200) {
                                    $.messager.alert('消息', data.msg);
                                } else {
                                    $.messager.alert('消息', data.msg);
                                    let dg = $('#dg');
                                    dg.datagrid('enableFilter');
                                    dg.datagrid('load');
                                    $('#supplyOfferWindow').window('close');
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                $.messager.alert('消息', errorThrown);
                            }
                        })
                    }
                    /**
                     * 查看报价详情
                     */
                    function viewDetails() {
                        let offerRow = $('#dataGridDiv').datagrid('getSelected');
                        if (!offerRow) {
                            $.messager.alert('提示', '请选择一条数据');
                            return
                        }
                        if (+offerRow.status != '1') {
                            $('#tabs').tabs({
                                tools: [{
                                    text: '提交',
                                    iconCls: 'icon-ok',
                                    handler: function () {
                                        $.messager.confirm('提示', '提交后无法再次编辑，确定要提交吗?',
                                            function (r) {
                                                if (r) {
                                                    saveSupplyOfferMM('submit');
                                                }
                                            });
                                    }
                                }]
                            })
                        } else {
                            $('#tabs').tabs({
                                tools: []
                            })
                        }

                        setOfferDetailWindowValue(offerRow)
                    }

                    function bingGrid() {
                        let dg = $('#dg');
                        let startTime = $('#startTime').datebox('getValue') ? $('#startTime').datebox('getValue') : ''
                        let endTime = $('#endTime').datebox('getValue') ? $('#endTime').datebox('getValue') : ''
                        let status = $('#status').combobox('getValue') ? $('#status').combobox('getValue') : ''
                        dg.datagrid({
                            title: '',
                            queryParams: {
                                startTime: startTime,
                                endTime: endTime,
                                status: status,
                                inqMode: '线下报价'
                            },
                            fitColumns: false,
                            fit: false,
                            url: 'purchase/offer/selectOfferList',
                            iconCls: 'icon-application',
                            clientPaging: false,
                            remoteFilter: true,
                            filterDelay: 0,
                            width: getWidth(0.98),
                            height: 400,
                            nowrap: true,
                            rownumbers: true,
                            animate: false,
                            collapsible: false,
                            singleSelect: true,
                            pageSize: 10,
                            remoteSort: false,
                            pagination: true,
                            frozenColumns: [[
                                {
                                    field: 'infId',
                                    title: '供应商id',
                                    hidden: true,
                                    formatter: function (val, rec, index) {
                                        return val ? val : '';
                                    }
                                },
                                {
                                    field: 'inqId',
                                    title: '询价id',
                                    hidden: true,
                                    formatter: function (val, rec, index) {
                                        return val ? val : '';
                                    }
                                },
                                {
                                    field: 'inqCode',
                                    title: '询价编码',
                                    formatter: function (val, rec, index) {
                                        return val ? val : '';
                                    }
                                },
                                {
                                    field: 'inqName',
                                    title: '询价名称',
                                    sortable: true,
                                    formatter: function (val, rec, index) {
                                        return '<a href="javascript:void(0)" onclick="openOfferDetail(' + index +
                                            ')">' + (val ? val : '') + '</a>'
                                        // return '<a href="javascript:void(0)" onclick="setOfferDetailWindowValue(' + index+')">' + (val ? val : '') + '</a>'
                                    }
                                },
                                {
                                    field: 'infName',
                                    title: '供应商名称',
                                    sortable: true,
                                    formatter: function (val, rec, index) {
                                        return (val ? val : '')
                                        // return '<a href="javascript:void(0)" onclick="setOfferDetailWindowValue(' + index+')">' + (val ? val : '') + '</a>'
                                    }
                                },
                            ]],
                            columns: [[
                                {
                                    field: 'inqOfrTime',
                                    title: '提交时间',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return unescape(val ? val : '')
                                    }
                                },
                                //                 {
                                //                     field: 'inqOfrIncludePrice',
                                //                     title: '计划名称',
                                //                     sortable: true,
                                //                     formatter: function (val, rec) {
                                //                         return unescape(val ? val : '')
                                //                     }
                                //                 },
                                {
                                    field: 'inqOfrTotalPrice',
                                    title: '合计价格',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return unescape(val ? val : 0)
                                    }
                                },
                                {
                                    field: 'inqOfrNum',
                                    title: '合计数量',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return unescape(val ? val : 0)
                                    }
                                },
                                {
                                    field: 'inqStartTime',
                                    title: '报价开始时间',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return unescape(val ? val : '')
                                    }
                                },
                                {
                                    field: 'inqEndTime',
                                    title: '报价结束时间',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return unescape(val ? val : '')
                                    }
                                },

                                {
                                    field: 'remark',
                                    title: '备注',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return unescape(val ? val : '')
                                    }
                                },
                                {
                                    field: 'createTime',
                                    title: '创建时间',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return unescape(val ? val : '')
                                    }
                                },
                                {
                                    field: 'createName',
                                    title: '创建人',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return unescape(val ? val : '')
                                    }
                                },
                                {
                                    field: 'status',
                                    title: '状态',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        let status = val ? val : '';
                                        return unescape(status == '0' ? '待报价' : '已报价');
                                    }
                                }
                            ]],
                            toolbar: [
                                {
                                    text: '报价',
                                    iconCls: 'icon-add',
                                    handler: function () {
                                        editRow();
                                    }
                                }
                                , '-',
                                {
                                    text: '撤回',
                                    iconCls: 'icon-undo',
                                    handler: function () {
                                        //撤回
                                        let row = $('#dg').datagrid('getSelected');
                                        if (row) {
                                            if (row.status == '0') {
                                                $.messager.alert('提示', '该单据未提交，无法撤回')
                                                return
                                            }
                                            $.messager.confirm('提示', '确定要撤回该报价吗?',
                                                function (r) {
                                                    if (r) {
                                                        backupOrder(row);
                                                    }
                                                });
                                        } else {
                                            $.messager.alert('消息', '请选择要撤回的报价。');
                                            return
                                        }
                                    }
                                }
                            ],
                            onLoadSuccess: function () {

                            },
                            onDblClickRow: function (rowIndex, rowData) {
                                editRow();
                            }
                        });
                        dg.datagrid('enableFilter');
                    }

                    function backupOrder(row) {
                        $.ajax({
                            type: 'get',
                            url: 'purchase/offer/backInquiryOffer?inqId=' + row.inqId + "&infId=" + row.infId,
                            // data: JSON.stringify(orderObj),
                            // contentType: "application/json",
                            dataType: 'json',
                            success: function (data) {
                                if (data.code == 60200) {
                                    $.messager.alert('消息', data.msg)
                                    let dg = $('#dg');
                                    dg.datagrid('enableFilter');
                                    dg.datagrid('load');
                                } else {
                                    $.messager.alert('消息', data.msg)
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                $.messager.alert('消息', errorThrown);
                            }
                        })
                    }
                </script>

                </html>